package com.example.config;


import com.example.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration //定义配置类
public class InterceptorConfig implements WebMvcConfigurer {
    public void addInterceptors(InterceptorRegistry registry) {
//        String[] addPathPatterns = {"/flowers/**"};
        String[] addPathPatterns = {"/**"};
        registry.addInterceptor(tokenInterceptor())
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns("/login","/swagger-resources/**","/error/**","/v2/**");
    }

    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();//实例化拦截器
    }

}
